﻿#include <iostream>
#include <string>
#include <tuple>
using namespace std;
//int stringdigitcheck(const string& s);
//int stringlettercheck(const string&);
//bool stringFinalCheck(const string&);
bool passwordcheck(const string&);
std::tuple<int, int,int>stringcheck(const string& s);
int main()
{
	string password;
	cout << "Please input your password" << endl;
	cin >> password;
	//cout << password.length() << endl;
	auto sign=passwordcheck(password);
	while (!sign)
	{
		cin >> password;
		sign = passwordcheck(password);
	}
	
}
bool passwordcheck(const string& password)
{
	int len, digitsum, lettersum;
	len = password.length();
	auto info = stringcheck(password);
	auto digit = get<0>(info);
	auto letter = get<1>(info);
	auto invalid = get<2>(info);//
	if (digit < 2 || password.length() < 8 || invalid > 0||digit==password.length()||letter==password.length())
	{
		cout << "password invalid" << endl;
		if (digit < 2)
		{
			cout << "A password must contain at least two digits" << endl;
		}
		if (password.length() < 8)
		{
			cout << "A password must contain 8 characters" << endl;
		}
		if (invalid > 0)
		{
			cout << "A password must consist of only letters and digits" << endl;
		}
		cout << "please input your password again"<< endl;
		return false;
	}
	else
	{
		cout << "valid password" << endl;
	}
	cout << digit << endl;
	//return 1;
}
std::tuple<int,int,int>stringcheck(const string& s)
{
	int i,digitsum=0,lettersum=0,invalidsum=0;
	for (i = 0; i < s.length(); i++)
	{
		if (isdigit(s[i]))
		{
			digitsum++;
		}
		else if (isalpha(s[i]))
		{
			lettersum++;
		}
		else
		{
			invalidsum++;
		}
	}
	for (i = 0; i < s.length(); i++)
	{
		if (isalpha(s[i]))
		{
			lettersum++;
		}
	}
	return make_tuple(digitsum, lettersum,invalidsum);
	//return digit;
}
/*int stringlettercheck(const string& s)
{
	int i, lettersum = 0;
	for (i = 0; i < s.length(); i++)
	{
		if (isalpha(s[i]))
		{
			lettersum++;
		}
	}
	//cout << lettersum << endl;
	return lettersum;
}*/
